/**
 * @a https://leetcode.cn/problems/roman-to-integer/
 */

#include "../common.h"

unordered_map<char, int> mp = {
    {'I',1},
    {'V',5},
    {'X',10},
    {'L',50},
    {'C',100},
    {'D',500},
    {'M',1000}
};
class Solution {
public:
    int romanToInt(string s){
        int ret = 0;
        int sz = s.size();
        for(int i = 0; i < sz; ++ i){
            int val = mp[s[i]];
            if(i < sz - 1 && val < mp[s[i + 1]])
                ret -= val;
            else
                ret += val;
        }
        return ret;
    }
};